//
//  CWSportMaskView.m
//  大神专制黑马行
//
//  Created by chenWei on 2017/5/17.
//  Copyright © 2017年 陈伟. All rights reserved.
//

#import "CWSportMaskView.h"

@interface CWSportMaskView ()

//@property(nonatomic, strong) IBOutletCollection(UIImageView) NSArray *imageViewArr;

@property(nonatomic, weak) IBOutlet UIImageView *imageView;


@end

@implementation CWSportMaskView
//加载视图的 XML 文件
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    
    return self;
}

//加载视图中的 xib（这里完成加载 storyboard 的属性）
//如果将视图中的子控件拖线到视图中，此方法会在视图加载前调用，否则会在视图加载后调用
- (void)awakeFromNib
{
    [super awakeFromNib];
    
    //清除背景颜色
    self.backgroundColor = [UIColor clearColor];
}

- (void)willMoveToWindow:(UIWindow *)newWindow
{
    [super willMoveToWindow:newWindow];
}

- (void)didMoveToWindow
{
    [super didMoveToWindow];
}

- (void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
}

- (void)didMoveToSuperview
{
    [super didMoveToSuperview];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}




#pragma mark - 绘制

//使用背景清除颜色必须满足一下条件：1.视图背景颜色必须为 clearColor，2.要想给背景设置颜色，值能使用路径填充的方法
- (void)drawRect:(CGRect)rect {
    
    //1.创建填充路径（以矩形填充）
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:self.bounds];
    
    //1.2.设置需要填充的颜色
    UIColor *color = [UIColor colorWithRed:36/255.f green:40/255.f blue:46/255.f alpha:1];

    //1.3.填充
    [color setFill];
    
    //1.4.使用当前贝塞尔路径填充绘制环境
    [bezierPath fill];
    
    
    
    //2.绘制线条路径
    UIBezierPath *linePath = [UIBezierPath bezierPath];
    //设置线宽
    [linePath setLineWidth:0.8];
    
    CGFloat maskViewW = self.frame.size.width;
    CGFloat maskViewH = self.frame.size.height;
    
    //判断是左边视图还是右边视图
    if (self.imageView.frame.origin.x > 0) {
        //左边视图
        
        //画线
        [linePath moveToPoint:CGPointMake(maskViewW, 0)];
        [linePath addLineToPoint:CGPointMake(maskViewW, maskViewH)];
        
    }else{
        //右边视图
        
        [linePath moveToPoint:CGPointMake(0, 0)];
        [linePath addLineToPoint:CGPointMake(0, maskViewH)];
        
    }
    
    //设置线条填充颜色
    UIColor *lineColor = [UIColor colorWithWhite:0.05 alpha:1];
    [lineColor setStroke];
    
    //贝塞尔描边
    [linePath stroke];
    
    
    //3.使用清除图层来清除颜色， 第一个参数：当前图层上下文    第二，三个参数：缩小像素
    CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectInset(self.imageView.frame, 1, 1));
    
    
}












@end
